package java8.lanmbda;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Scenes {
	public static interface NoArg{
		void doIt();
	}
	public static interface SingleArg{
		void doIt(int i);
	}
	public static interface MultiArg{
		void doIt(int i,int j);
	}
	public static void main(String[] args) {
		need(()->System.out.println("heihei"));
		need((int i)->System.out.println(i));
		need((i)->System.out.println(i));
		need(i->System.out.println(i));
		need((int i,int j)->System.out.println(i+j));
		need(()->{
			int i=0;
			System.out.println(i);
		});
		
		List<Person> persons = Arrays.asList(new Person[]{new Person(3, "3岁"),new Person(1, "1岁"),new Person(2, "2岁")});
		//TODO 为什么能访问private变量
		Collections.sort(persons, (a,b)->{
			return a.age-b.age;
		});
		Collections.sort(persons, (a,b)->{
			return a.compareAge(b);
		});
		Collections.sort(persons,Person::compareAge);
		
		persons.forEach(t->System.out.println(t));
		persons.forEach(Person::showName);
	}
	
	private static void need(NoArg noArg) {
		noArg.doIt();
	}
	private static void need(SingleArg singleArg) {
		singleArg.doIt(1);
	}
	private static void need(MultiArg multiArg) {
		multiArg.doIt(1,2);
	}
	
	public static class Person{
		private int age;
		private String name;
		public Person(int age, String name) {
			super();
			this.age = age;
			this.name = name;
		}
		public int getAge() {
			return age;
		}
		public int compareAge(Person person) {
			return this.age-person.age;
		}
		public static void showName(Person p) {
			System.out.println(p.name);
		}
		public void setAge(int age) {
			this.age = age;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		@Override
		public String toString() {
			return "Person [age=" + age + ", name=" + name + "]";
		}
	}
}
